<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<% String path = request.getContextPath(); %>
<html>
<head>
    <title>nucleic</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="icon" href="<%=path%>/images/favicon.ico" sizes="32x32"/>
    <link rel="stylesheet" href="<%=path%>/css/font.css">
    <link rel="stylesheet" href="<%=path%>/css/xadmin.css">
    <script type="text/javascript" src="<%=path%>/js/jquery-1.3.2.min.js"></script>
    <script src="<%=path%>/lib/layui/layui.js"></script>
    <script type="text/javascript" src="<%=path%>/js/xadmin.js"></script>
    <script src="<%=path%>/layui_exts/excel.js"></script>
    <style type="text/css">
        .layui-table {
            text-align: center;
        }

        .layui-table th {
            text-align: center;
        }
    </style>
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
       <a href="">首页</a>
        <a href="<%=path%>/rubbish/reportCollector">举报回收员</a>
      </span>
</div>
<div class="x-body">
    <%--添加模态框--%>
    <div class="layui-row" id="test">
        <div class="layui-col-md10">
            <form class="layui-form" id="addRubbishForm">
                <div style="margin-top: 20px;"></div>
                <div class="layui-form-item">
                    <label class="layui-form-label">回收员姓名：</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" class="layui-input" placeholder="请输入回收员姓名">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">回收物品：</label>
                    <div class="layui-input-block">
                        <input type="text" name="rubbishName" class="layui-input" placeholder="请输入回收的物品">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">举报原因：</label>
                    <div class="layui-input-block">
                        <input type="text" name="reason" class="layui-input" placeholder="请输入举报原因">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">提交
                        </button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <script>
        layui.config({
            base: 'layui_exts/',
        });

        layui.use(['jquery', 'form', 'layer', 'laydate'], function () {
            var form = layui.form,
                $ = layui.jquery,
                laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
            });
            /*添加弹出框*/
            form.on('submit(formDemo)', function (data) {
                var param = data.field;
                $.ajax({
                    url: '<%=path%>/rubbish/reportRubbishCollector',
                    type: "post",
                    data: JSON.stringify(param),
                    contentType: "application/json; charset=utf-8",
                    success: function (res) {
                        if (res.code === 200) {
                            layer.msg('添加成功', {icon: 1, time: 3000});
                        }
                        return false;
                    },
                    error: function () {
                        layer.msg('添加失败', {icon: 0, time: 3000});
                        setTimeout(function () {
                            window.location.href = '<%=path%>/resident/findResident';
                        }, 2000);
                    }
                });
            });

        });

        /*编辑*/
        function residentEditBtn(id) {
            $.ajax({
                url: '<%=path%>/resident/findResidentById?id=' + id,
                type: "get",
                contentType: "application/json; charset=utf-8",
                dataType: 'json', //添加这一条语句
                success: function (res) {
                    layui.use(['jquery', 'form', 'layer', 'laydate'], function () {
                        var form = layui.form, $ = layui.jquery;
                        layer.open({
                            type: 1,
                            title: "编辑",
                            skin: "myclass",
                            area: ["50%"],
                            anim: 2,
                            content: $("#edit"),
                            success: function () {
                            }
                        });
                        $("#editResidentForm")[0].reset();
                        document.getElementById("id").value = res.id;
                        document.getElementById("username").value = res.username;
                        document.getElementById("password").value = res.password;
                        document.getElementById("realname").value = res.realname;
                        document.getElementById("sex").value = res.sex;
                        document.getElementById("phone").value = res.phone;
                        document.getElementById("idcard").value = res.idcard;
                        document.getElementById("community").value = res.community;
                        document.getElementById("address").value = res.address;
                        document.getElementById("place").value = res.place;
                        form.on('submit(formEditDemo)', function (data) {
                            var param = data.field;
                            $.ajax({
                                url: '<%=path%>/resident/updateResident',
                                type: "post",
                                data: JSON.stringify(param),
                                contentType: "application/json; charset=utf-8",
                                success: function (res) {
                                    if (res == '202') {
                                        layer.msg('用户名重复，请更改后重试！', {icon: 0, time: 3000});
                                    } else {
                                        layer.msg('修改成功', {icon: 1, time: 3000});
                                        setTimeout(function () {
                                            window.location.href = '<%=path%>/resident/findResident';
                                        }, 2000);
                                    }
                                },
                                error: function () {
                                    layer.msg('修改失败', {icon: 0, time: 3000});
                                    setTimeout(function () {
                                        window.location.href = '<%=path%>/resident/findResident';
                                    }, 2000);
                                }
                            });
                        });
                    });
                },
                error: function () {
                    layer.msg('获取失败', {icon: 0, time: 3000});
                    setTimeout(function () {
                        window.location.href = '<%=path%>/resident/findResident';
                    }, 2000);
                }
            });
        }


        /*删除*/
        function member_del(obj, id) {
            layer.confirm('确认要删除吗？', function (index) {
                //发异步删除数据
                $.get("<%=path%>/resident/deleteResident", {"id": id}, function (data) {
                    if (data = true) {
                        layer.msg('删除成功!', {icon: 1, time: 2000});
                        setTimeout(function () {
                            window.location.href = '<%=path%>/resident/findResident';
                        }, 2000);

                    } else {
                        layer.msg('删除失败!', {icon: 1, time: 2000});
                        setTimeout(function () {
                            window.location.href = '<%=path%>/resident/findResident';
                        }, 2000);
                    }
                });
            });
        }

        /*加入高危人员*/
        function warn(obj, id) {
            layer.confirm('确认要移入高危人员管理吗？', function (index) {
                //发异步删除数据
                $.get("<%=path%>/resident/warn", {"id": id}, function (data) {
                    if (data == '200') {
                        layer.msg('加入高危人员成功!', {icon: 1, time: 2000});
                        setTimeout(function () {
                            window.location.href = '<%=path%>/resident/findResident';
                        }, 2000);
                    } else {
                        layer.msg('加入高危人员失败!', {icon: 1, time: 2000});
                        setTimeout(function () {
                            window.location.href = '<%=path%>/resident/findResident';
                        }, 2000);
                    }
                });
            });
        }
    </script>
</body>
</html>
